package book

import (
	"NovelBook/dao"
	"NovelBook/models/db_models"
)

func SearchBookByIsbn(str string) ([]db_models.Books, error) {
	var book []db_models.Books
	err := dao.GetDb().Where("isbn = ?", str).Find(&book).Error
	if err != nil {
		return nil, err
	}
	return book, nil
}

func SearchBookByName(str string) ([]db_models.Books, error) {
	var book []db_models.Books
	err := dao.GetDb().Where("name = ?", str).Find(&book).Error
	if err != nil {
		return nil, err
	}
	return book, nil
}
func SearchBookByAuthor(str string) ([]db_models.Books, error) {
	var book []db_models.Books
	err := dao.GetDb().Where("author = ?", str).Find(&book).Error
	if err != nil {
		return nil, err
	}
	return book, nil
}
func SearchBookByPublisher(str string) ([]db_models.Books, error) {
	var book []db_models.Books
	err := dao.GetDb().Where("publisher = ?", str).Find(&book).Error
	if err != nil {
		return nil, err
	}
	return book, nil
}
func SearchBookById(id int) ([]db_models.Books, error) {
	var book []db_models.Books
	err := dao.GetDb().Where("id = ?", id).Find(&book).Error
	if err != nil {
		return nil, err
	}
	return book, nil
}
func SearchBookByKind(str string) ([]db_models.Books, error) {
	var book []db_models.Books
	err := dao.GetDb().Where("Kind = ?", str).Find(&book).Error
	if err != nil {
		return nil, err
	}
	return book, nil
}
